/**
 * File:         $HeadURL: http://protoext.googlecode.com/svn/trunk/prototools.js $
 * 
 * Description:  js prototype tools
 *
 * @autor        Mamontov Andrey <andrvm@andrvm.ru>
 * @copyright    Mamontov Andrey (andrvm) 2009 - 2010
 * @prototype	 >= 1.5.1
 * 
 * @license      MIT
 * 
 * @date		 $Date: 2010-09-19 16:16:41 +0000 (Sun, 19 Sep 2010) $
 * @revision	 $Revision: 11 $
 * @changeby	 $Author: andr.v.mamontov $
 * 
 */
 
 var ProtoTools = function(){
 	
 	/**
 	 * Properties
 	 */
 	
 	// version
 	this.version 	= '0.01',
 	// useragent
 	this.userAgent 	= navigator.userAgent.toLowerCase(),
 	// browser
 	this.browser	= {
 			version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
			safari: /webkit/.test( userAgent ),
			opera: /opera/.test( userAgent ),
			msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
			mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ),
			chrome:	/chrome/.test( userAgent )
 	},
 	
 	
 	/**
 	 * Methods
 	 */
 	
 	// user's timezone
 	// @copyright Josh Fraser (http://www.onlineaspect.com)
 	// http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/
 	this.userTz = function (){
 		
 			var rightNow  = new Date();
 			// jan 1st
			var jan1 	  = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
			// june 1st
			var june1 	  = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
			var temp 	  = jan1.toGMTString();
			var jan2 	  = new Date(temp.substring(0, temp.lastIndexOf(' ')-1));
			
			temp = june1.toGMTString();
			
			var june2 = new Date(temp.substring(0, temp.lastIndexOf(' ')-1));
			var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
			var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
			
			var dst;
			
			if (std_time_offset == daylight_time_offset) {
				// daylight savings time is NOT observed
				dst = '0'; 
			} else {
				// positive is southern, negative is northern hemisphere
				var hemisphere = std_time_offset - daylight_time_offset;
				if (hemisphere >= 0)
					std_time_offset = daylight_time_offset;
				// daylight savings time is observed
				dst = '1'; 
			}
	
			return {'dst': dst, 'offset': std_time_offset, 'utc': this._convertTz(std_time_offset)};			
 	},
 	
 	this._convertTz = function(value) {
	
			var hours = parseInt(value);
   			value 	 -= parseInt(value);
			value 	 *= 60;
			
			var mins  = parseInt(value);
   			value 	 -= parseInt(value);
			value 	 *= 60;
			
			var secs  = parseInt(value);
			var display_hours = hours;
			
			// handle GMT case (00:00)
			if (hours == 0) {
				display_hours = '00';
			} else if (hours > 0) {
				// add a plus sign and perhaps an extra 0
				display_hours = (hours < 10) ? '+0' + hours : '+' + hours;
			} else {
				// add an extra 0 if needed 
				display_hours = (hours > -10) ? '-0' + Math.abs(hours) : hours;
			}
	
			mins = (mins < 10) ? '0' + mins : mins;
			
			return display_hours + ':' + mins;
 	} 
 }
 
 ProtoTools = new ProtoTools();